<!-- 设置 -->
<template>
	<view>
		<view class="inner">
			<view class="logo">
				<image src="/static/logo.png" mode=""></image>
			</view>
			<view class="handle">
				<!-- #ifdef APP-PLUS -->
				<view class="item" @click="getUpdate" v-if="!isios">
					<view>版本更新</view>
					<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/mine/right.png"></image>
				</view>
				<!-- #endif -->
				<view class="item" @click="goUpdate" v-if='hasPassword==1'>
					<view>修改密码</view>
					<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/mine/right.png"></image>
				</view>
				<view class="item" @click="setPwd" v-else>
					<view>设置密码</view>
					<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/mine/right.png"></image>
				</view>
				<view class="item last" @click="cancelAccount">
					<view>注销账号</view>
					<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/mine/right.png"></image>
				</view>
			</view>

			<view class="btn" @click="showUnLogin = true">退出登录</view>

			<view class="copyright">
				<text style="color: #275ed2;" @click="goPrivacy">《隐私政策》</text>
				<text>客服电话：15295610310</text>
				<text>联系邮箱：yizhiqygl@163.com</text>
				<text>江苏已知企业管理有限公司 版权所有</text>
				<text>Copyright©2021-2022</text>
			</view>
		</view>
		<!-- 退出登录 -->
		<u-modal :show="showUnLogin" title="提示" content="确认退出登录?" showCancelButton @cancel="showUnLogin = false"
			@confirm="confirm" />
		<!-- 注销账号弹出层 -->
		<zero-buy :isShow='cancelShow' :isCancel='true' @cancel='cancels' @submit='submit'></zero-buy>

		<!-- 更新 -->
		<upDatePopup :show.sync="showUpdate"></upDatePopup>
		</view>
</template>

<script>
	import {
		cancelAccount
	} from '@/apis/apis.js';
	import ZeroBuy from '@/components/zeroBuy/zeroBuy.vue'
	import upDatePopup from "@/pages/components/upDate_popup.vue"
	export default {
		components: {
			ZeroBuy,upDatePopup
		},
		data() {
			return {
				showUnLogin: false,
				showUpdate: false,
				showDownload: false, // 开始下载
				isLatest: true, // 是否最新
				percentage: 0,
				appVersion: '',
				cancelShow: false, //注销账号弹出
				timer: null,
				hasPassword: -1, //0是用户没设置密码，1用户设置了密码
				isios:false
			};
		},
		onLoad(options) {
			this.hasPassword = options.hasPassword ? options.hasPassword : 0
			let that = this
			uni.getSystemInfo({
				success: function(res) {
					if(res.platform == 'ios'){
						that.isios = true
					}
				}
			})
		},
		onUnload() {
			clearTimeout(this.timer)
			this.timer = null
		},
		methods: {
			goPrivacy() {
				uni.navigateTo({
					url: `/pages/argeement/userArgeement?type=0`
				})
			},
			// 获取版本更新
			async getUpdate() {
				this.showUpdate = true;
			},
			// 退出登录
			confirm() {
				uni.removeStorageSync('token');
				uni.removeStorageSync('USER_DATA')
				uni.removeStorageSync('shareData')
				uni.removeStorageSync('stamp')
				uni.removeStorageSync('currentPage')
				uni.reLaunch({
					url: '/pages/login/login'
				});
			},
			//设置密码
			setPwd() {
				console.log('设置密码');
				uni.navigateTo({
					url: './updatePwd?set=1'
				});
			},
			//注销账号
			cancelAccount() {
				console.log('注销');
				this.cancelShow = true
			},
			//取消注销
			cancels() {
				this.cancelShow = false
			},
			//确认注销
			submit() {
				console.log('注销');
				cancelAccount().then(res => {
					console.log(res, '注销账号')
					uni.showToast({
						title: '注销成功',
						icon: 'none'
					})
					uni.clearStorageSync()
					this.timer = setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}, 1000)
				})
			},
			// 修改密码
			goUpdate() {
				uni.navigateTo({
					url: './updatePwd?set=2'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	::v-deep .u-safe-bottom{
		/* #ifdef H5 || MP-WEIXIN */
		display: none;
		/* #endif */
	}
	.inner {
		min-height: calc(100vh - var(--status-bar-height));
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
		padding: 0 70rpx;

		.logo {
			width: 180rpx;
			height: 180rpx;
			border-radius: 40rpx;
			overflow: hidden;
			&>image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.handle {
		width: 100%;

		.item {
			display: flex;
			justify-content: space-between;
			font-size: 30rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			padding: 36rpx 0;
			color: #111111;
			border-bottom: 1rpx solid #e9eefa;

			&>image {
				width: 14rpx;
				height: 26rpx;
			}
		}

		.last {
			border: none;
		}
	}

	.btn {
		width: 420rpx;
		height: 80rpx;
		background: #ebecf1;
		border-radius: 40rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #acadb4;
	}

	.copyright {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 26rpx;
		color: #acadb4;

		&>text {
			margin-bottom: 5rpx;
		}
	}
</style>
